package servlet;

import entity.Room;
import service.RoomService;
import service.impl.RoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(urlPatterns = "/RoomInsetServlet")
public class RoomInsetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String roomName = request.getParameter("roomName");
        int computerNumber = Integer.parseInt(request.getParameter("computerNumber"));
        String manager = request.getParameter("manager");
        String location = request.getParameter("location");
        int state = Integer.parseInt(request.getParameter("state"));

        Room room  = new Room();
        room.setState(state);
        room.setLocation(location);
        room.setManager(manager);
        room.setComputerNumber(computerNumber);
        room.setRoomName(roomName);

        RoomService roomService  = new RoomServiceImpl();
        int i = roomService.inset(room);
        if (i>0){
            request.getRequestDispatcher("room/room_All.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
